<template>
  <div>
    <el-dialog title="提示" :visible.sync="showDatas" width="50%%">
      <el-form :model="ruleForm" :rules="rules" ref="ruleFormRef" label-width="100px" class="demo-ruleForm">
        <el-form-item label="文章标题" prop="title">
          <el-input v-model="ruleForm.title"></el-input>
        </el-form-item>
        <el-form-item label="文章内容" prop="articleBody">
          <el-input v-model="ruleForm.articleBody"></el-input>
        </el-form-item>
        <el-form-item label="视频地址">
          <el-input v-model="ruleForm.videoURL"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="btncol">取 消</el-button>
        <el-button type="primary" @click="putData">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { addList } from '@/api/user'
export default {
  props: {
    showDatas: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      ruleForm: {
        title: '',
        articleBody: '',
        videoURL: ''
      },
      rules: {
        title: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
        articleBody: [{ required: true, message: '请输入活动名称', trigger: 'blur' }]
      }
    }
  },
  created: function() {},
  methods: {
    async putData() {
      try {
        this.$refs.ruleFormRef.validate()
        await addList(this.ruleForm)
        this.$parent.getList()
        this.$parent.showDatas = false
        this.$message.success('添加成功')
      } catch (error) {
        this.$message.error('error')
      }
      this.ruleForm = {
        title: '',
        articleBody: '',
        videoURL: ''
      }
    },
    btncol() {
      this.ruleForm = {
        title: '',
        articleBody: '',
        videoURL: ''
      }
      this.$refs.ruleFormRef.resetFields()
      this.$emit('update:showDatas', false)
    }
  }
}
</script>
<style scoped></style>
